#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#define FIFO "./fifo"

int main()
{
	int ret = mkfifo(FIFO,0644);
	if(ret < 0)
	{
		perror("mkfifo");
		return 1;
	}
	int fd = open(FIFO,O_RDONLY);
	if(fd < 0)
	{
		perror("open");
		return 2;
	}

	char buffer[128];
	while(1)
	{
		buffer[0] = 0;
		ssize_t s = read(fd,buffer,sizeof(buffer)-1);
		if(s > 0)
		{
			buffer[s] = 0;
			printf("client: %s\n",buffer);
		}
		else if(s == 0)
		{
			printf("client quit...\n");
			break;
		}
		else
			break;
	}
	close(fd);
	return 0;
}
